package com.example.administrator.myproject.Adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.myproject.JavaBean.AllSorts;
import com.example.administrator.myproject.R;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/12.
 */

public class AllsortsAdapter extends BaseAdapter {
    private String BASR_URL1 = "http://pimg.damai.cn/perform/project/";
    private List<AllSorts> mAllsorts;
    private Context context;
    private LayoutInflater inflater;


  public   void setData(List<AllSorts> mAllsorts) {
        this.mAllsorts = mAllsorts;
//        notifyDataSetChanged();
    }

    public AllsortsAdapter(Context context, List<AllSorts> allSorts) {
        this.context = context;
        this.mAllsorts = allSorts;
        inflater = LayoutInflater.from(context);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mAllsorts.size();
    }

    @Override
    public Object getItem(int i) {
        return mAllsorts.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (view == null) {
            view = inflater.inflate(R.layout.all_layout, viewGroup, false);
            holder = new ViewHolder();
            holder.image = (ImageView) view.findViewById(R.id.iv_all);
            Log.i("TAG","===image");
            holder.tvName = (TextView) view.findViewById(R.id.tv_name);
            holder.tvticket = (TextView) view.findViewById(R.id.tv_ticket);
            holder.tvtoday = (TextView) view.findViewById(R.id.tv_today);
            holder.tvvenName = (TextView) view.findViewById(R.id.tv_venName);
            holder.tvpriceName = (TextView) view.findViewById(R.id.tv_priceName);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        AllSorts allSorts = mAllsorts.get(i);
        String imageUrl = allSorts.getI();

        final String imageURI = BASR_URL1 + imageUrl.substring(0, 4) + "/" + imageUrl + "_n.jpg";
        Log.i("TAG","===imageURI"+imageURI.toString());


        Picasso.with(context).load(imageURI).into(holder.image);
        holder.tvName.setText(allSorts.getName());
        Log.i("TAG","===data"+allSorts.getName().toString());
        holder.tvticket.setText("剩余票数" + allSorts.getTicket());
        holder.tvtoday.setText(allSorts.getToday());
        holder.tvvenName.setText(allSorts.getVenName());
        holder.tvpriceName.setText(allSorts.getPriceName());

        return view;
    }



    class ViewHolder {
        ImageView image;
        TextView tvName, tvticket, tvtoday, tvvenName, tvpriceName;
    }
}
